import axios from 'axios'

import { getToken } from '@/utils/auth'

//axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
//

const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API,
    timeout: 1000
})

service.interceptors.request.use(config => {
    const isToken = (config.headers || {}).isToken === false
    if (getToken() && !isToken) {
        config.headers['Authorization'] = 'Bearer ' + getToken()
    }

    console.log(config)
    return config
})

service.interceptors.response.use(res => {
    const code = res.data.code || 200;
    console.log('1.code:' + code)
    return res.data
})

export default service
